<?php
function run($bin,$file_arr,$arg)
{
	$process = array();
	for($i=0;$i<count($file_arr);$i++)
	{
		echo 'Start '.$file_arr[$i].' ... ';
		open_process($process[$i],$bin.' '.$file_arr[$i].' '.$arg, 'r');
		echo 'ok'.chr(10);
	}

	while(1)
	{
		for($i=0;$i<count($file_arr);$i++)
		{
			fread($process[$i],256);					
		}
		sleep(3);
	}
	echo 'done';
}
function open_process(&$rs, $cmd, $mode = 'r')
{
	$rs = popen($cmd, $mode);
}
$service_file = array('service_game.php','service_login.php','service_main.php');
if(!isset($argv[1])||intval($argv[1])<1)
{
	printf('%c[5;31mServer NO. must be a positive integer.%cYour command should similar as ./run 1 .%c[0m\n',27,10,27);
	die();
}
$server_no = intval($argv[1]);

run('php',$service_file,$server_no);